﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietTrips.Domain.Services;
using VietTrips.WebUI.Areas.Management.Models;
using VietTrips.WebUI.Filters;
using VietTrips.WebUI.Infrastructure;

namespace VietTrips.WebUI.Areas.Management.Controllers
{
    [InitializeSimpleMembership]
    public class AdminController : Controller
    {
        private readonly StatisticsService _statisticsService = new StatisticsService();
        //
        // GET: /Management/Admin/
        [Authorize(Roles = "Administrator, Agency")]
        public ActionResult Dashboard()
        {
            ViewBag.NumberOfUsers = _statisticsService.NumberOfUsers;
            return View();
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult Settings()
        {
            var model = new AdminSettingsModel
            {
                AdminEmail = AppSettings.AdministatorEmail,
                AppName = AppSettings.ApplicationName
            };
            return View("AdminSettings", model);
        }

        [Authorize(Roles = "Administrator")]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Settings(AdminSettingsModel model)
        {
            AppSettings.ApplicationName = model.AppName;
            AppSettings.AdministatorEmail = model.AdminEmail;
            return View("AdminSettings", model);
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult MapSettings()
        {
            return RedirectToAction("Dashboard", "Admin");
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult TemplateSettings()
        {

            return RedirectToAction("Dashboard", "Admin");
        }
    }
}
